#include "newfriendwidget.h"
#include "ui_newfriendwidget.h"


NewFriendWidget::NewFriendWidget(const QString& friendId, const QString& nickname, const QString& verifyInfo,
                                const QDateTime& applyTime, const int& id,
                                const QString& alias, const FriendVerifyStatus& status, QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::NewFriendWidget)
{
    ui->setupUi(this);

    m_friendId = friendId;
    m_nickname = nickname;
    m_verifyInfo = verifyInfo;
    m_applyTime = applyTime;
    m_id = id;

    m_status = status;
    m_alias = alias;

    initUI();
}

NewFriendWidget::~NewFriendWidget()
{
    delete ui;
}

QPushButton* NewFriendWidget::getBtnCheck()
{
    return ui->btnCheck;
}

QString NewFriendWidget::getFriendId() const
{
    return m_friendId;
}

QString NewFriendWidget::getNickname() const
{
    return m_nickname;
}

QString NewFriendWidget::getVerifyInfo() const
{
    return m_verifyInfo;
}

int NewFriendWidget::getId() const
{
    return m_id;
}

void NewFriendWidget::setStatus(const FriendVerifyStatus& status)
{
    m_status = status;
    refreshUI();
}

void NewFriendWidget::initUI()
{
    // 设置字体颜色
    ui->labelUserId->setStyleSheet("color: black;");
    ui->labelNickname->setStyleSheet("color: black;");
    ui->labelDateTime->setStyleSheet("color: black;");

    ui->labelUserId->setText(m_friendId);
    ui->labelNickname->setText(m_nickname);
    // 格式化为 "yyyy-MM-dd hh:mm"
    QString formattedDate = m_applyTime.toString("yyyy-MM-dd hh:mm");
    ui->labelDateTime->setText(formattedDate);

    QString qss = R"(
    QPushButton {
        background-color: #FBE6E5;
        border: 2px solid pink;
        color: grey;
        border-radius: 10px;
    }
    QPushButton:hover {
        background-color: #F7DADA;
    }
    QPushButton:pressed {
        background-color: #FFCFD5;
    }
    )";
    ui->btnCheck->setStyleSheet(qss);

    // 根据status决定按钮的状态
    refreshUI();

}


// 更新UI
void NewFriendWidget::refreshUI()
{
    if (m_status == FriendVerifyStatus::Unverified)
    {
        ui->btnCheck->setText(tr("查看"));
        ui->btnCheck->setEnabled(true);
    }
    else
    {
        ui->btnCheck->setText(tr("已完成"));
        ui->btnCheck->setEnabled(false);
    }
}
